-
Notifications
You must be signed in to change notification settings - Fork 3
[FEATURE] Add Data API support with routing metadata headers and pagination #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] Add Data API support with routing metadata headers and pagination #26
Conversation
…nation (LRN-49154)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds comprehensive Data API support to the Ruby SDK, enabling authenticated requests with automatic pagination and routing metadata headers. The implementation follows the Node.js SDK pattern and includes Ruby 2.6 compatibility fixes for the Rails quickstart application.
Key Changes:
- New
DataApiclass with three iteration methods:request()for single requests,request_iter()for page iteration, andresults_iter()for individual result iteration - Automatic routing metadata headers (
X-Learnosity-Consumer,X-Learnosity-Action,X-Learnosity-SDK) added to all Data API requests - Ruby 2.6 compatibility fixes including commented-out gems requiring Ruby 2.7+ and logger initialization
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
lib/learnosity/sdk/request/data_api.rb |
Core DataApi class implementation with request signing, pagination, and metadata headers |
lib/learnosity/sdk.rb |
Exports DataApi class for convenient access |
spec/learnosity/sdk/request/data_api_spec.rb |
Unit tests for DataApi methods and error handling |
spec/integration/data_api_spec.rb |
Integration tests for request signing and API version handling |
examples/simple/data_api_example.rb |
Example demonstrating three iteration patterns |
docs/quickstart/lrn-sdk-rails/app/controllers/data_api_controller.rb |
Rails controller demonstrating Data API usage |
docs/quickstart/lrn-sdk-rails/app/views/data_api/index.html.erb |
View displaying Data API demo results |
docs/quickstart/lrn-sdk-rails/config/routes.rb |
Added route for Data API demo |
docs/quickstart/lrn-sdk-rails/config/boot.rb |
Added logger require for Ruby 2.6 compatibility |
docs/quickstart/lrn-sdk-rails/Gemfile |
Commented out spring gems for Ruby 2.6 compatibility |
docs/quickstart/lrn-sdk-rails/app/views/index/index.html.erb |
Added link to Data API demo |
REFERENCE.md |
Documentation for DataApi class usage |
README.md |
Updated with Ruby 2.6 compatibility notes and Data API references |
ChangeLog.md |
Release notes for Data API feature and compatibility fixes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| mock_adapter = lambda do |url, signed_request, headers| | ||
| expect(url).to eq('https://data.learnosity.com/v1/itembank/items') | ||
| expect(headers['X-Learnosity-Consumer']).to eq(config[:consumer_key]) | ||
| expect(headers['X-Learnosity-Action']).to eq('get_/itembank/items') |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test verifies the derived action format but doesn't test the actual derivation logic with different endpoint structures. Consider adding tests that verify derive_action is called with the correct endpoint parameter.
| # Verify security contains signature | ||
| security = JSON.parse(captured_request[:signed_request]['security']) | ||
| expect(security['signature']).to be_a(String) | ||
| expect(security['signature']).to start_with('$02$') |
Copilot
AI
Dec 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hardcoded signature format '$02$' is a magic string. Consider extracting this to a constant or adding a comment explaining what '$02$' represents in the signature format.
docs/quickstart/lrn-sdk-rails/app/controllers/data_api_controller.rb
Outdated
Show resolved
Hide resolved
docs/quickstart/lrn-sdk-rails/app/views/data_api/index.html.erb
Outdated
Show resolved
Hide resolved
docs/quickstart/lrn-sdk-rails/app/controllers/data_api_controller.rb
Outdated
Show resolved
Hide resolved
anthony-murphy-lrn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
| http = Net::HTTP.new(uri.host, uri.port) | ||
| http.use_ssl = (uri.scheme == 'https') | ||
|
|
||
| request = Net::HTTP::Post.new(uri.request_uri, headers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to think about get?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the Learnosity Data API docs, it looks like the API always uses HTTP POST, even for "get" actions. The action parameter ('get', 'set', 'update', 'delete') isn't the HTTP method - it's a Learnosity-specific action type that goes in the request body.
| def default_http_adapter(endpoint, signed_request, headers) | ||
| uri = URI.parse(endpoint) | ||
| http = Net::HTTP.new(uri.host, uri.port) | ||
| http.use_ssl = (uri.scheme == 'https') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be setting timeouts for the requests?
Summary
Adds comprehensive Data API support to the Ruby SDK, following the pattern established in the Node.js SDK.
Changes
Core Implementation
DataApiclass (lib/learnosity/sdk/request/data_api.rb)request()- Make single authenticated Data API requestsrequest_iter()- Iterate through paginated responses (returns Enumerator)results_iter()- Iterate through individual results across pages (returns Enumerator)X-Learnosity-Consumer,X-Learnosity-Action,X-Learnosity-SDKRails Quickstart Integration
app/controllers/data_api_controller.rbapp/views/data_api/index.html.erb/data_api/indexRuby 2.6 Compatibility Fixes
springandspring-watcher-listengems (require Ruby 2.7+)require 'logger'toconfig/boot.rbfor Rails 6.1 compatibilityTesting
spec/learnosity/sdk/request/data_api_spec.rbspec/integration/data_api_spec.rbexamples/simple/data_api_example.rbDocumentation
REFERENCE.mdwith Data API usage examplesREADME.mdwith Ruby version compatibility notesTesting
All existing tests pass. New tests added for Data API functionality.